# 把当前项目根目录加入Python环境路径
import sys
sys.path.append('/www/wwwroot/panda-ai')

from models.user_keys import UserKey, UsedLog
from models.base import get_db


def query_all_keys():
    db = next(get_db())
    try:
        # 查询所有key记录
        all_keys = db.query(UserKey).all()
        print("所有key:")
        for key in all_keys:
            print(f"ID: {key.id}, Key: {key.key}, 剩余次数: {key.remainder}")
        all_usedlogs = db.query(UsedLog).all()
        print("所有使用日志:")
        for usedlog in all_usedlogs:
            print(f"ID: {usedlog.id}, Key: {usedlog.key}, 最后使用时间: {usedlog.lastime}, IP: {usedlog.ip}, UserAgent: {usedlog.useragent}")
    except Exception as e:
        print(f'查询失败! {e}')

if __name__ == "__main__":
    query_all_keys() 